package thread;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/27
 * Time:20:47
 * 出让CPU执行权
 **/
public class ThreadDemo17 {
    private static final int maxSize = 1000;

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < maxSize; i++) {
                //出让CPU执行权
                Thread.yield();
                System.out.println("我是t1");
            }
        },"t1");
        t1.start();

        Thread t2 = new Thread(()->{
            for (int i = 0; i < maxSize; i++) {
                System.out.println("我是t2");
            }
        },"t2");
        t2.start();
    }
}
